package com.example.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.erp.domain.DataResult;
import com.example.erp.dto.QueryUserInfoDTO;
import com.example.erp.entity.UserInfo;
import com.example.erp.log.LogPrint;
import com.example.erp.mapper.UserInfoMapper;
import com.example.erp.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 18481
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Resource
    private UserInfoService userInfoService;

    @Resource
    private UserInfoMapper userInfoMapper;

    @GetMapping("/test")
    @LogPrint
    public DataResult<List<UserInfo>> test(@RequestParam @NotBlank(message = "bu能为空") String id) {
        log.info("ssssssss{}", id);
        List<UserInfo> list = userInfoService.list();
        DataResult<List<UserInfo>> result = new DataResult<>();
        result.setResult(list);
        return result;
    }

    @PostMapping("/test2")
    @LogPrint
//    @TokenRequired(value = false)
    public DataResult<UserInfo> test2(@RequestBody @Valid QueryUserInfoDTO queryUserInfoDTO) {
        log.warn("warn");
        log.error("error");
        UserInfo one = userInfoService.getOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getId, queryUserInfoDTO.getId()));
        return DataResult.success(one, UserInfo.class);
    }
}
